package view;

import model.LessonGuide;
import model.Lesson.RepeatMode;
import eventHandling.Callback;
import eventHandling.EventBus;
import eventHandling.EventTyp.Type;

public class CreateNewLessonDialogController implements Controller{

	private EventBus eventBus;
	private CreateNewLessonDialog cnlDialog;
	private LessonGuide lessonGuide;
	
	public CreateNewLessonDialogController(EventBus eventBus,
			CreateNewLessonDialog cnlDialog, LessonGuide lessonGuide) {
		this.eventBus = eventBus;
		this.cnlDialog = cnlDialog;
		this.lessonGuide = lessonGuide;
		registerForEvents();
	}

	
	private void registerForEvents() {
		
		eventBus.register(Type.OPEN_NEW_LESSON_DIALOG, new Callback() {

			public void actionPerformed() {
				cnlDialog.setVisible(true);
			}
		});
		
		eventBus.register(Type.CLOSE_CREATE_LESSON_DIALOG, new Callback() {

			public void actionPerformed() {
				cnlDialog.setVisible(false);

			}
		});

		eventBus.register(Type.CREATE_NEW_LESSON, new Callback() {

			public void actionPerformed() {
				
				
				RepeatMode repeatMode = RepeatMode.REMEMBER;
				if(cnlDialog.getRepeatModeIndex() == 0) {
					repeatMode = RepeatMode.REMEMBER;
				}
				
				lessonGuide.createNewLesson(repeatMode, cnlDialog
						.isOnlyVocabularySelected(), cnlDialog.getDescription());
				
				cnlDialog.setVisible(false);
				
			}
		});
	}
}
